package cn.e4j.modular.crm.controller.base;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.core.shiro.ShiroKit;
import cn.e4j.core.shiro.ShiroUser;
import cn.e4j.core.util.LangUtils;
import cn.e4j.modular.crm.entity.GwcqT;
import cn.e4j.modular.crm.entity.GwcqzT;
import cn.e4j.modular.crm.mapper.GwcqTMapper;
import cn.e4j.modular.crm.service.impl.Gwai700ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 购物车控制类
 *
 * @author yuan_rz
 * @Date 2019/01/15 14:54
 */
@Controller
@RequestMapping("/base/gwai700")
public class Gwai700Controller extends BaseController {

    @Autowired
    private Gwai700ServiceImpl gwai700Service;

    @Autowired
    private GwcqTMapper gwcqTMapper;

    /**
     * 跳转页面
     */
    @RequiresPermissions("base:gwai700:init")
    @RequestMapping(value = {"", "init"})
    public String index() {
        return "/pc/crm/base/gwai700.html";
    }

    /**
     * 查询列表数据
     */
    @RequestMapping("/getListData")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData getListData(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        Dto inDto = dtoWapper.getDto();
        List<Dto> result = gwai700Service.getListData(page, inDto);
        return new PageReData(page, result);
    }

    /**
     * 导出Excel
     */
    @RequestMapping(value = "/exportListData", method = RequestMethod.GET)
    @RequiresPermissions("base:gwai700:init")
    public void exportListData(ModelMap map, HttpServletRequest request, HttpServletResponse response) {

    }

    /**
     * 添加数据
     */
    @RequestMapping("/addData")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData addData(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwcqT> gwcqTList = inDto.getReqList(GwcqT.class);
        gwai700Service.addData(gwcqTList);
        return SUCCESS_TIP;
    }

    /**
     * 添加数据
     */
    @RequestMapping("/saveData")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData saveData(GwcqT gwcqT) {
        gwai700Service.saveData(gwcqT);
        return SUCCESS_TIP;
    }

    /**
     * 修改数据
     */
    @RequestMapping("/editData")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData editData(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwcqT> gwcqTList = inDto.getReqList(GwcqT.class);
        gwai700Service.editData(gwcqTList);
        return SUCCESS_TIP;
    }

    /**
     * 删除数据
     */
    @RequestMapping("/deleteData")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData deleteData(GwcqT gwcqT) {
        gwai700Service.deleteData(gwcqT);
        return SUCCESS_TIP;
    }

    /**
     * 删除数据
     */
    @RequestMapping("/deleteGwcq")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData deleteGwcq(GwcqT gwcqT) {
        gwai700Service.deleteGwcq(gwcqT);
        return SUCCESS_TIP;
    }

    /**
     * 批量删除数据
     */
    @RequestMapping("/deleteDataBatch")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData deleteDataBatch(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwcqT> gwcqTList = inDto.getReqList(GwcqT.class);
        gwai700Service.deleteDataBatch(gwcqTList);
        return SUCCESS_TIP;
    }

    /**
     * 转订单
     */
    @RequestMapping("/transformOrder")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData transformOrder(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwcqT> gwcqTList = inDto.getReqList(GwcqT.class);
        gwai700Service.transformOrder(gwcqTList);
        return SUCCESS_TIP;
    }

    /**
     * 部分转订单
     */
    @RequestMapping("/transformOrderPart")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData transformOrderPart(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwcqT> gwcqTList = inDto.getReqList(GwcqT.class);
        gwai700Service.transformOrderPart(gwcqTList);
        return SUCCESS_TIP;
    }

    /**
     * 转询价单
     */
    @RequestMapping("/transformInquiry")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData transformInquiry(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwcqT> gwcqTList = inDto.getReqList(GwcqT.class);
        gwai700Service.transformInquiry(gwcqTList);
        return SUCCESS_TIP;
    }

    /**
     * 获取新增数据
     */
    @RequestMapping("/getAddData")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData getAddData(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ENT", shiroUser.getDBC());
        inDto.put("LANG", LangUtils.getLang(shiroUser.getLANG()));
        Dto addDataDto = gwai700Service.getAddData(inDto);
        return new SuccessResponseData(addDataDto);
    }

    /**
     * 批量修改数据
     */
    @RequestMapping("/getUpdateData")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData getUpdateData(@DtoParam DtoWapper dtoWapper) {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = dtoWapper.getDto();
        inDto.put("ENT", shiroUser.getDBC());
        inDto.put("LANG", LangUtils.getLang(shiroUser.getLANG()));
        List<Dto> updateDtoList = gwai700Service.getUpdateData(inDto);
        return new SuccessResponseData(updateDtoList);
    }

    /**
     * 法人组织开窗
     */
    @RequestMapping("/getFrzzList")
    @ResponseBody
    public ResponseData getFrzzList(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        Dto inDto = dtoWapper.getDto();
        List<Dto> result = gwcqTMapper.getFrzzList(page, inDto);
        return new PageReData(page, result);
    }

    /**
     * 查询赠品列表数据
     */
    @RequestMapping("/getGiftInfoData")
    @ResponseBody
    public ResponseData getGiftInfoData(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<Dto> result = gwai700Service.getGiftInfoData(inDto);
        return new SuccessResponseData(result);
    }

    /**
     * 查询活动列表数据
     */
    @RequestMapping("/getGwdcOpenData")
    @ResponseBody
    public ResponseData getGwdcOpenData(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        Dto inDto = dtoWapper.getDto();
        List<Dto> result = gwai700Service.getGwdcOpenData(page, inDto);
        return new PageReData(page, result);
    }

    /**
     * 查询赠品开窗列表数据
     */
    @RequestMapping("/getGwdczOpenData")
    @ResponseBody
    public ResponseData getGwdczOpenData(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        Dto inDto = dtoWapper.getDto();
        List<Dto> result = gwai700Service.getGwdczOpenData(page, inDto);
        return new PageReData(page, result);
    }

    /**
     * 添加赠品数据
     */
    @RequestMapping("/addGwcqzData")
    @ResponseBody
    public ResponseData addGwdczData(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwcqzT> gwcqzTList = inDto.getReqList(GwcqzT.class);
        gwai700Service.addGwcqzData(gwcqzTList);
        return SUCCESS_TIP;
    }

    /**
     * 查询产品信息列表
     */
    @RequestMapping("/getGwdc020_021")
    @ResponseBody
    public ResponseData getGwdc020_021(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        Dto outDto = gwai700Service.getGwdc020_021(inDto);
        return ResponseData.success(outDto);
    }

    /**
     * 动态删除赠品信息
     */
    @RequestMapping("/delGwcqzByGwcqz007")
    @ResponseBody
    public ResponseData delGwcqzByGwcqz007(@DtoParam DtoWapper dtoWapper) {
        Dto outDto = Dtos.newDto();
        Dto inDto = dtoWapper.getDto();
        gwai700Service.delGwcqzByGwcqz007(inDto);
        return ResponseData.success(outDto);
    }

    /**
     * 删除数据
     */
    @RequestMapping("/deleteGwcqBatch")
    @RequiresPermissions("base:gwai700:init")
    @ResponseBody
    public ResponseData deleteGwcqBatch(GwcqT gwcqT) {
        gwai700Service.deleteGwcqBatch(gwcqT);
        return SUCCESS_TIP;
    }
}
